package org.fhm.zdte.common.pojo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * An object that encapsulates the information of the currently online user of the server.
 *
 * @author 谭波
 * @since 2023/12/22
 */
public class UserGroup {

    private List<User> users;

    /**
     * A constructor that encapsulates online users.
     *
     * @param container      The currently online user.
     * @param identification The client side identification.
     */
    public UserGroup(Map<String, Address> container, String identification) {
        users = new ArrayList<>();
        for (Map.Entry<String, Address> entry : container.entrySet()) {
            String userId = entry.getKey();
            if (!identification.equals(userId)) {
                UserGroup.User user = new UserGroup.User();
                user.setUserId(userId);
                user.setAddress(entry.getValue());
                users.add(user);
            }
        }
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    @Override
    public String toString() {
        return "UserGroup{" +
                "users=" + users +
                '}';
    }

    public static final class User implements Serializable {

        private static final long serialVersionUID = 5215720748342549833L;

        private Address address;

        private String userId;

        public Address getAddress() {
            return address;
        }

        public void setAddress(Address address) {
            this.address = address;
        }

        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }

        @Override
        public String toString() {
            return "User{" +
                    "address=" + address +
                    ", userId='" + userId + '\'' +
                    '}';
        }
    }
}
